home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / DJGPP / grdj.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  4KB  |  216 lines

  1. /* --------------------------------- grdj.c --------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Vga graphics driver (direct tseng4000 access, 256 colors only).
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12. #include <graphics.h>
  13. #include <pc.h>
  14. #include <dos.h>
  15.  
  16.  
  17. #define INITED        0x1000
  18.  
  19. #define inp(p)         inportb(p)
  20. #define outp(p,b)    outportb(p,b)
  21.  
  22. #define GrOR    0x200
  23.  
  24. static int _GrWriteMode = 0;
  25. static Uint x = 0, y = 0;
  26.  
  27. LOCAL_FUNC void FAR
  28. DjDrawTo (Uint x2, Uint y2, Uint c)
  29. {
  30.     GrLine (x, y, x2, y2, _GrWriteMode|c);
  31.     x = x2;
  32.     y = y2;
  33. }
  34.  
  35. LOCAL_FUNC void FAR
  36. DjMoveTo (Uint x1, Uint y1)
  37. {
  38.     x = x1;
  39.     y = y1;
  40. }
  41.  
  42. LOCAL_FUNC int FAR
  43. DjSetActive (int page)
  44. {return (0);}
  45.  
  46. LOCAL_FUNC int FAR
  47. DjSetVisual (int page)                /* done */
  48. {return (0);}
  49.  
  50. LOCAL_FUNC int FAR
  51. DjSetWriteMode (int mode)
  52. {
  53.     switch (mode) {
  54.     default:
  55.     case T_MSET:
  56.         _GrWriteMode = 0;
  57.         break;
  58.     case T_MOR:
  59.         _GrWriteMode = GrOR;
  60.         break;
  61.     case T_MXOR:
  62.         _GrWriteMode = GrXOR;
  63.         break;
  64.     }
  65.     return (0);
  66. }
  67.  
  68. LOCAL_FUNC void FAR
  69. DjClear (int x, int y, int sizex, int sizey, Uint color)
  70. {
  71.     for (sizey += y, sizex += x-1;y < sizey; ++y)
  72.         GrLine (x, y, sizex, y, color);
  73. }
  74.  
  75. LOCAL_FUNC int FAR
  76. DjSetPalette (int index, long c)
  77. {
  78.     GrSetColor (index, C_RGB_R (c), C_RGB_G (c), C_RGB_B (c));
  79.     return (0);
  80. }
  81.  
  82. LOCAL_FUNC int FAR
  83. DjSetBiosMode (int n)
  84. {
  85.     union REGS    regs;
  86.  
  87.     if (n >= 0x100) {
  88.         regs.x.ax = 0x4f02;
  89.         regs.x.bx = n;
  90.     } else
  91.         regs.x.ax = n;
  92.     return (int86 (0x10, ®s, ®s));
  93. }
  94.  
  95. LOCAL_FUNC int FAR
  96. DjInit (DEVICE *dev, char *options)
  97. {
  98.     int    i;
  99.     long    temp;
  100.  
  101.     if (dev->sizex == 0 || dev->sizey == 0)
  102.         return (1);
  103.  
  104.     GrSetMode (GR_width_height_graphics, dev->sizex, dev->sizey);
  105.  
  106. #if 1
  107.     if (dev->mode > 0)
  108.         DjSetBiosMode (dev->mode);
  109. #endif
  110.     dev->npages = 1;
  111.     for (i = 0; i++ < 256 && GrAllocCell () >= 0;)    /* get 2-255 */
  112.         ;
  113.  
  114.     DjSetWriteMode (T_MSET);
  115.     DjSetPalette (CC_BLACK, C_BLACK);
  116.     for (i = 0; i < dev->npages; ++i) {
  117.         DjSetActive (i);
  118.         DjClear (0, 0, dev->sizex, dev->sizey, st.colors[CC_BLACK]);
  119.     }
  120.  
  121.     DjSetVisual (0);
  122.     DjSetActive (0);
  123.  
  124.     if (get_narg (options, "shutters=", &temp))
  125.         st.misc[7] = (int)temp;
  126.     else
  127.         st.misc[7] = 0;
  128.  
  129.     Gr->flags |= INITED;
  130.  
  131.     return (0);
  132. }
  133.  
  134. LOCAL_FUNC void FAR
  135. DjTerm (DEVICE *dev)        /* done */
  136. {
  137.     if (!(Gr->flags & INITED))
  138.         return;
  139.     Gr->flags &= ~INITED;
  140.  
  141.     GrSetMode (GR_default_text, 0, 0);
  142.     DjSetBiosMode (0x03);
  143. }
  144.  
  145. LOCAL_FUNC void FAR
  146. DjEllipse (register Uint x1, register Uint y1, Uint rx, Uint ry, 
  147.     register Uint color)
  148. {
  149.     int    ax, bx, cx, dx, ay, by, cy, dy;
  150.  
  151.     ax = fmul ( 3196, rx);        /* sin (pi/16) */
  152.     ay = fmul ( 3196, ry);
  153.     bx = fmul ( 9102, rx);        /* sin (3*pi/16) */
  154.     by = fmul ( 9102, ry);
  155.     cx = fmul (13623, rx);        /* sin (5*pi/16) */
  156.     cy = fmul (13623, ry);
  157.     dx = fmul (16069, rx);        /* sin (7*pi/16) */
  158.     dy = fmul (16069, ry);
  159.  
  160.     DjMoveTo (x1+dx, y1-ay);
  161.     DjDrawTo (x1+cx, y1-by, color);
  162.     DjDrawTo (x1+bx, y1-cy, color);
  163.     DjDrawTo (x1+ax, y1-dy, color);
  164.     DjDrawTo (x1-ax, y1-dy, color);
  165.     DjDrawTo (x1-bx, y1-cy, color);
  166.     DjDrawTo (x1-cx, y1-by, color);
  167.     DjDrawTo (x1-dx, y1-ay, color);
  168.     DjDrawTo (x1-dx, y1+ay, color);
  169.     DjDrawTo (x1-cx, y1+by, color);
  170.     DjDrawTo (x1-bx, y1+cy, color);
  171.     DjDrawTo (x1-ax, y1+dy, color);
  172.     DjDrawTo (x1+ax, y1+dy, color);
  173.     DjDrawTo (x1+bx, y1+cy, color);
  174.     DjDrawTo (x1+cx, y1+by, color);
  175.     DjDrawTo (x1+dx, y1+ay, color);
  176.     DjDrawTo (x1+dx, y1-ay, color);
  177. }
  178.  
  179. LOCAL_FUNC int FAR
  180. DjShutters (int eye)
  181. {
  182.     if (st.misc[7]) {
  183.         if (eye >= 0)
  184.             outp (st.misc[7]+4, 1+2*eye);
  185.         else if (-1 == eye)
  186.             outp (st.misc[7]+4, 1);        /* on */
  187.         else if (-2 == eye)
  188.             outp (st.misc[7]+4, 0);        /* off */
  189.         return (0);                /* have shutters */
  190.     } else
  191.         return (1);                /* no shutters */
  192. }
  193.  
  194. struct GrDriver NEAR GrDJ = {
  195.     "GrDJ",
  196.     0,
  197.     NULL,    /* extra */
  198.     0,
  199.     DjInit,
  200.     DjTerm,
  201.     DjMoveTo,
  202.     DjDrawTo,
  203.     DjSetVisual,
  204.     DjSetActive,
  205.     0,    /* Clear() too slow */
  206.     DjSetWriteMode,
  207.     DjSetPalette,
  208.     DjEllipse,
  209.     0,    /* Flush */
  210.     DjShutters
  211. };
  212. #undef inp
  213. #undef outp
  214. #undef GrOR
  215. #undef INITED
  216.